<template>
  <div>
    <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.prevent.native>
      <el-form-item :label="$t('指标名称')" prop="keyName">
        <el-input
          v-model="queryParams.keyName"
          :placeholder="$t('指标名称')"
          clearable
          :onsubmit="false"
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>

      <el-table ref="multipleTable" v-loading="loading" :data="pcwWarningList" border>
        <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('指标名称')" prop="keyName" :show-overflow-tooltip="true" width="150" />
        <el-table-column :label="$t('指标值')" align="center" prop="keyValue" show-overflow-tooltip />
        <el-table-column :label="$t('上下行预警')" align="center" prop="warmUpDown" show-overflow-tooltip :formatter="riskTypeFormat" />
        <el-table-column :label="$t('预警线')" align="center" prop="warnLine" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ moneyFormat(scope.row.warnLine) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('报警线')" align="center" prop="alarmLine" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ moneyFormat(scope.row.alarmLine) }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
  </div>

</template>

<script>
import { dealPcwWarningList } from '@/api/company/pcw/pcwRiskMonitor'
export default {
  data() {
      return {
          // 遮罩层
          loading: true,
          // 预警数据
          pcwWarningList: [],
          // 总条数
          total: 0,
          // 查询参数
          queryParams: {
              keyName: '',
              companyId: '',
              riskType: '',
              mainId: ''
          },
          // 表单校验
          rules: {},
          // 上下行预警
          riskTypeOptions: []
      }
  },
  created() {
    this.getDicts('risk_monitor_type').then(response => {
      this.riskTypeOptions = response.data
    })
  },
  methods: {
    // 注册资本币种字典翻译
    riskTypeFormat(row) {
      return this.selectDictLabel(this.riskTypeOptions, row.warmUpDown)
    },
    /** 查询关注科目列表 */
    init(data) {
      if (data !== undefined) {
        this.queryParams.mainId = data.mainId
        this.queryParams.riskType = data.riskType
        this.queryParams.companyId = data.companyId
        this.loading = true
        dealPcwWarningList(data).then(response => {
          this.pcwWarningList = response.rows
          this.total = response.total
          this.loading = false
        })
      }
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.init(this.queryParams)
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      this.$parent.$parent.formOpen = false
      // 刷新list页面
      this.$parent.$parent.getList()
    }
  }
}
</script>
